<?php

namespace Medicina\KernelBundle\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;

/**
 * Medicina\KernelBundle\Entity\Catedra
 *
 * @ORM\Table(name="catedra")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="Medicina\KernelBundle\Entity\CatedraRepository")
 */
class Catedra {

    /**
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @ORM\Column(name="codigo", type="string", length=10, nullable=true, unique=false)
     */
    private $codigo;

    /**
     * @ORM\Column(name="nombre", type="string", length=50, nullable=false, unique=true)
     */
    private $nombre;

    /**
     *  @ORM\OneToMany(targetEntity="Cargo", mappedBy="catedra")
     */
    private $cargos;

    /**
     *  @ORM\OneToMany(targetEntity="Concurso", mappedBy="catedra", cascade={"persist"})
     */
    private $concursos;

    public function __construct() {
        $this->cargos = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function addConcursos(\Medicina\KernelBundle\Entity\Concurso $concursos) {
        $this->concursos[] = $concursos;
    }

    public function getConcursos() {
        return $this->concursos;
    }

    public function setConcursos($concursos) {
        foreach ($concursos as $concurso) {
            $this->setConcurso($concurso);
        }
    }

    public function setConcurso($concurso) {
        $inpugnacion->setConcurso($this);
        $this->addConcursos($concurso);
    }

    public function getId() {
        return $this->id;
    }

    public function setCodigo($codigo) {
        $this->codigo = $codigo;
    }

    public function getCodigo() {
        return $this->codigo;
    }

    public function setNombre($nombre) {
        $this->nombre = $nombre;
    }

    public function getNombre() {
        return $this->nombre;
    }

    public function addCargo(\Medicina\KernelBundle\Entity\Cargo $cargos) {
        $this->cargos[] = $cargos;
    }

    public function getCargos() {
        return $this->cargos;
    }

    public function __toString() {
        return $this->getNombre();
    }
    
    public function esBorrable(){
        return ($this->getCargos()->isEmpty() AND $this->getConcursos()->isEmpty());
    }

    /**
     * Add concursos
     *
     * @param Medicina\KernelBundle\Entity\Concurso $concursos
     */
    public function addConcurso(\Medicina\KernelBundle\Entity\Concurso $concursos)
    {
        $this->concursos[] = $concursos;
    }
}